home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16124 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: news.magmacom.com!not-for-mail
  2. From: ezust@mag1.magmacom.com (Acme Instant Dehydrated Boulder Kit)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ complex numbers slow as molasses?
  5. Date: 9 Apr 1996 13:04:24 -0400
  6. Organization: Cloud-Zero, Canada
  7. Message-ID: <4ke5ap$b8b@mag1.magmacom.com>
  8. References: <4k6k8c$8h4@nyx.cs.du.edu> <9604071851.AA001o1@lorelei.demon.co.uk>
  9. NNTP-Posting-Host: mag1.magmacom.com
  10.  
  11. In article <9604071851.AA001o1@lorelei.demon.co.uk>,
  12. John Croudy  <john@lorelei.demon.co.uk> wrote:
  13. >On 6 Apr 1996 13:30:04 -0700, A. N. Alias wrote:
  14. >
  15. >> bit slower, but I thought that the speed difference would
  16. >> be far less drastic (esp. if the C++ compiler inlines the
  17. >> arithmetic operators, as the Complex.h declarations specify).
  18. >
  19. >As far as I understand it, GNU only inlines if you have optimisations
  20. >turned up quite high.  Like -O4 or something.  Well, that's what I've
  21. >found from experience of Gnu C++ Version 2.7
  22. >
  23.  
  24. Another problem you might be facing is, if you wrote in C your arithmetic
  25. operations as 3-argument functions passing pointers to structs for all 3
  26. arguments, then it would definitely be more efficient than using overloaded
  27. non-side-effeciting binary operators...
  28.  
  29. I don't know how the gnu library is implemented, but it probalby works
  30. something like this:
  31.  
  32. Complex a,b,c;
  33.  
  34.   a = b + c;    // creates a temporary local in operator+,
  35.         // returns that temporary local by value on the stack
  36.         // performs an assignment
  37.  
  38. But if you wrote a member function called
  39.        add(const complex&a, const complex&b)
  40.  
  41. which made "this" be the sum of a and b, you don't have any tempoaries being
  42. created... This can significantly speed up your code.
  43.  
  44. non side-effecting binary operators usually are slower than writing regular
  45. (member) functions which take 3 (2) parameters by reference/pointer, placing
  46. the result into one of the parameters (or *this).
  47.  
  48.  
  49. -- 
  50. Alan Ezust                       "Just because I work for the federal
  51. Ottawa, Canada                    government doesn't mean I'm an expert
  52. ezust@magmacom.com                on cockroaches"  -Special Agent Fox Mulder
  53. http://www2.magmacom.com/~ezust   
  54.